<template>
  <div class="divBox relative">
    <el-card class="box-card">
      <div class="clearfix">
        <div class="container">
          <el-form inline size="small" label-width="120px" @submit.native.prevent>
            <el-form-item :label="$t('halykDingDanHao')+'：'">
              <el-input
                v-model="tableFrom.haOrderCode"
                :placeholder="$t('qingShuRuHalykDingDanHao')"
                class="selWidth"
                size="small"
                clearable
              >
                <el-button slot="append" icon="el-icon-search" size="small" @click="seachList" />
              </el-input>
            </el-form-item>
          </el-form>
        </div>
      </div>
    </el-card>
    <div class="mt20" />
    <el-card class="box-card">
      <el-table
        v-loading="listLoading"
        :data="tableData.data"
        size="mini"
        class="table"
        highlight-current-row
        :header-cell-style="{ fontWeight: 'bold' }"
        row-key="id"
        @selection-change="onSelectTab"
      >
        <el-table-column type="selection" width="55" />
        <el-table-column prop="merIdList" :label="$t('shangHuId')" min-width="100" />
        <el-table-column prop="haOrderCode" :label="$t('halykDingDanHao')" min-width="180" />
        <!-- <el-table-column prop="orderCode" :label="$t('zhuDingDanHao')" min-width="180" /> -->
        <el-table-column prop="storeNameList" :label="$t('shangPinMingCheng')" min-width="180" />
        <el-table-column prop="skuCodeList" label="SKU" min-width="180" />
        <el-table-column prop="countPlace" :label="$t('dingDanShangPinZhongShu')" min-width="100"/>
        <el-table-column prop="postagePrice" :label="$t('zongYunFei')" min-width="100" />
        <el-table-column prop="totalPrice" :label="$t('shiJiZhiFu')" min-width="100" />
        <el-table-column :label="$t('dingDanZhuangTai')" min-width="100" prop="statusDesc" />
        <el-table-column prop="createTime" :label="$t('xiaDanShiJian')" min-width="150" />
        <el-table-column :label="$t('caoZuo')" min-width="180" fixed="right" align="center">
          <template slot-scope="scope">
            <el-button
              v-if="scope.row.status==='SHIPPED'"
              type="text"
              size="small"
              @click.native="callCourier(scope.row.id)"
            >{{scope.row.orderType==='PHYSICAL_PICKUP'? '发送OTP': $t('huJiaoKuaiDiYuan') }}
            </el-button>
            <el-button v-if="scope.row.changeExpressNumberStatus==='Y'&&scope.row.endLabelPath" type="text" @click="saveAs(scope.row.endLabelPath)">{{ $t('xiaZai') }}</el-button>
            <el-button
              type="text"
              size="small"
              @click.native="onOrderDetails(scope.row.id)"
            >{{ $t('dingDanXiangQing') }}
            </el-button>
          </template>
        </el-table-column>
      </el-table>
      <div class="block">
        <el-pagination
          :page-sizes="[20, 40, 60, 80]"
          :page-size="tableFrom.limit"
          :current-page="tableFrom.page"
          layout="total, sizes, prev, pager, next, jumper"
          :total="tableData.total"
          @size-change="handleSizeChange"
          @current-change="pageChange"
        />
      </div>
    </el-card>

    <!--详情-->
    <details-from ref="orderDetail" />
  </div>
</template>

<script>
import { changeExpressListApi,callCourierApi } from '@/api/halykOrder'
import detailsFrom from './halykOrderDetail'
import { checkPermi } from '@/utils/permission' // 权限判断函数
export default {
  components: {
    // cardsData,
    detailsFrom
  },
  data() {
    return {
      tableDataLog: {
        data: [],
        total: 0
      },
      tableData: {
        data: [],
        total: 0
      },
      listLoading: true,
      tableFrom: {
        status: '',
        dateLimit: '',
        haOrderCode: '',
        postagePrice: '',
        page: 1,
        limit: 20
      },
      timeVal: [],
      selectionList: [],
    }
  },
  mounted() {
    this.getList()
    // this.getOrderStatusNum()
  },
  methods: {
    checkPermi,
    seachList() {
      this.tableFrom.page = 1
      this.getList()
      // this.getOrderStatusNum()
    },
    // 详情
    onOrderDetails(id) {
      this.$refs.orderDetail.getDetail(id)
      this.$refs.orderDetail.dialogVisible = true
    },
    // 选择时间
    selectChange(tab) {
      this.timeVal = []
      this.tableFrom.page = 1
      this.getList()
      // this.getOrderStatusNum()
    },
    // 具体日期
    onchangeTime(e) {
      this.timeVal = e
      this.tableFrom.dateLimit = e ? this.timeVal.join(',') : ''
      this.tableFrom.page = 1
      this.getList()
      // this.getOrderStatusNum()
    },
    // 列表
    getList() {
      this.listLoading = true
      changeExpressListApi(this.tableFrom)
        .then((res) => {
          this.tableData.data = res.list.map(item=>{
            item.merIdList = item.merIdList.join(',')
            item.storeNameList = item.storeNameList.join(',')
            item.skuCodeList = item.skuCodeList.join(',')
            return item
          }) || []
          this.tableData.total = res.total
          this.listLoading = false
        })
        .catch(() => {
          this.listLoading = false
        })
    },
    pageChange(page) {
      this.tableFrom.page = page
      this.getList()
    },
    handleSizeChange(val) {
      this.tableFrom.limit = val
      this.getList()
    },
    // 全选
    onSelectTab(selection) {
      this.selectionList = selection
    },
    callCourier(id){
      this.$modalSure('货已到仓库').then(() => {
        this.listLoading = true
        callCourierApi({orderIds:[id]})
          .then((res) => {
            // 关闭loading 在getList 里面
            this.$message.success(this.$t('caoZuoChengGong'));
            this.getList()
          })
          .catch(() => {
            this.listLoading = false
          })
      })
    },
    saveAs(url, name) {
      window.open(url, '_blank');
    },
    // 详情
    onOrderDetails(id) {
      this.$refs.orderDetail.getDetail(id)
      this.$refs.orderDetail.dialogVisible = true
    },
  }
}
</script>
<style lang="scss" scoped>
.red {
  color: #ed4014;
}
.el-table__body {
  width: 100%;
  table-layout: fixed !important;
}

.demo-table-expand {
  ::v-deeplabel {
    width: 83px !important;
  }
}

.refunding {
  span {
    display: block;
  }
}

.selWidth {
  width: 300px;
}

.el-dropdown-link {
  cursor: pointer;
  color: #409eff;
  font-size: 12px;
}

.el-icon-arrow-down {
  font-size: 12px;
}

.tabBox_tit {
  font-size: 12px !important;
  /*margin: 0 2px 0 10px;*/
  letter-spacing: 1px;
  /*padding: 5px 0;*/
  box-sizing: border-box;
}

.text_overflow {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 400px;
}

.pup_card {
  width: 200px;
  border-radius: 5px;
  padding: 5px;
  box-sizing: border-box;
  font-size: 12px;
  line-height: 16px;
}

.flex-column {
  display: flex;
  flex-direction: column;
}

.mt20 {
  margin-top: 20px;
}

.relative {
  position: relative;
}

.card_abs {
  position: absolute;
  padding-bottom: 15px;
  top: 340px;
  right: 40px;
  width: 200px;
  background: #fff;
  z-index: 99999;
  box-shadow: 0px 0px 14px 0px rgba(0, 0, 0, 0.1);
}

.cell_ht {
  height: 50px;
  padding: 15px 20px;
  box-sizing: border-box;
  border-bottom: 1px solid #eeeeee;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.check_cell {
  width: 100%;
  padding: 15px 20px 0;
}

::v-deep .el-checkbox__input.is-checked + .el-checkbox__label {
  color: #606266;
}
</style>
